package com.yanfan.iot.tdengine.dao;

import com.yanfan.zutai.domain.BDeviceHistoryData;
import com.yanfan.zutai.domain.vo.BDeviceRealDataLineVo;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @package com.yanfan.mysql.mysql.tdengine
 * 类名: DatabaseMapper
 * 时间: 2022/5/16,0016 1:27
 * 开发人: wxy
 */
public interface ZuTaiTDengineMapper {


    /***
     * 创建超级表
     */
    @Update(" CREATE STABLE if not exists ${database}.`b_device_history_data`\n"
            + "    (`report_time` TIMESTAMP,\n"
            + "        `dept_id_strs` NCHAR(255),\n"
            + "        `device_imei` NCHAR(50),\n"
            + "        `device_name` NCHAR(50),\n"
            + "        `param_name` NCHAR(20),\n"
            + "        `param_field` NCHAR(50),\n"
            + "        `param_value` DOUBLE,\n"
            + "        `param_unit` NCHAR(10))\n"
            + "    TAGS (`id` BIGINT UNSIGNED) ")
    int createDeviceHistoryDataSTable(String database);

    /***
     * 执行sql
     */
    @Update("${updateSql}")
    void updateBySql(String updateSql);

    /***
     * 查询实时数据
     */
    @Select("${selectSql}")
    List<BDeviceHistoryData> getRealDataList(String selectSql);

    @Select("${selectSql}")
    List<BDeviceHistoryData> selectBDeviceHistoryDataTaosList(String selectSql);

    @Select("${countSql}")
    Long countBDeviceHistoryDataTaos(String countSql);

    @Select("${selectSql}")
    List<BDeviceRealDataLineVo> getVariableLine(String sql);

    @Select("${selectSql}")
    List<BDeviceRealDataLineVo> getVariableLines(String sql);

}
